package org.reliablesource.prism.gef.editor.commands;

import org.eclipse.gef.commands.Command;
import org.reliablesource.prism.gef.editor.model.ScreenAdapter;
import org.reliablesource.prism.gef.editor.model.StickyNoteAdapter;


/**
 * A command to remove a PolygonModel from its ScreenAdapter.
 * The command can be undone or redone.
 */
public class StickyNoteDeleteCommand extends Command {
	
	/** StickyNote to remove. */
	private final StickyNoteAdapter stickyNote;
	
	/** ScreenAdapter to remove from. */
	private final ScreenAdapter screen;
	
	/** True, if stickyNote was removed from its screen. */
	private boolean wasRemoved;
	
	/**
	 * Create a command that will remove the stickyNote from its screen.
	 * @param screen the ScreenAdapter containing the stickyNote
	 * @param stickyNote the PolygonModel to remove
	 * @throws IllegalArgumentException if any parameter is null
	 */
	public StickyNoteDeleteCommand(ScreenAdapter diagram, StickyNoteAdapter polygon) {
		if (diagram == null || polygon == null) {
			throw new IllegalArgumentException();
		}
		setLabel("stickyNote deletion");
		this.screen = diagram;
		this.stickyNote = polygon;
	}
	
	
	/* (non-Javadoc)
	 * @see org.eclipse.gef.commands.Command#canUndo()
	 */
	public boolean canUndo() {
		return wasRemoved;
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.gef.commands.Command#execute()
	 */
	public void execute() {
		redo();
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.gef.commands.Command#redo()
	 */
	public void redo() {
		wasRemoved = screen.removeChild(stickyNote);
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.gef.commands.Command#undo()
	 */
	public void undo() {
		screen.addChild(stickyNote);
	}
}